home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / mod_proxy.h.z / mod_proxy.h
C/C++ Source or Header  |  2002-07-08  |  10KB  |  282 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  *
  54.  * Portions of this software are based upon public domain software
  55.  * originally written at the National Center for Supercomputing Applications,
  56.  * University of Illinois, Urbana-Champaign.
  57.  */
  58.  
  59. #ifndef MOD_PROXY_H
  60. #define MOD_PROXY_H 
  61.  
  62. /*
  63.  * Main include file for the Apache proxy
  64.  */
  65.  
  66. /*
  67.  
  68.    Also note numerous FIXMEs and CHECKMEs which should be eliminated.
  69.  
  70.    This code is once again experimental!
  71.  
  72.    Things to do:
  73.  
  74.    1. Make it completely work (for FTP too)
  75.  
  76.    2. HTTP/1.1
  77.  
  78.    Chuck Murcko <chuck@topsail.org> 02-06-01
  79.  
  80.  */
  81.  
  82. #define CORE_PRIVATE
  83.  
  84. #include "apr_hooks.h"
  85. #include "apr.h"
  86. #include "apr_compat.h"
  87. #include "apr_lib.h"
  88. #include "apr_strings.h"
  89. #include "apr_buckets.h"
  90. #include "apr_md5.h"
  91. #include "apr_network_io.h"
  92. #include "apr_pools.h"
  93. #include "apr_strings.h"
  94. #include "apr_uri.h"
  95. #include "apr_date.h"
  96. #include "apr_fnmatch.h"
  97. #define APR_WANT_STRFUNC
  98. #include "apr_want.h"
  99.  
  100. #include "httpd.h"
  101. #include "http_config.h"
  102. #include "ap_config.h"
  103. #include "http_core.h"
  104. #include "http_protocol.h"
  105. #include "http_request.h"
  106. #include "http_vhost.h"
  107. #include "http_main.h"
  108. #include "http_log.h"
  109. #include "http_connection.h"
  110. #include "util_filter.h"
  111. #include "util_ebcdic.h"
  112.  
  113. #if APR_HAVE_NETINET_IN_H
  114. #include <netinet/in.h>
  115. #endif
  116. #if APR_HAVE_ARPA_INET_H
  117. #include <arpa/inet.h>
  118. #endif
  119.  
  120. /* for proxy_canonenc() */
  121. enum enctype {
  122.     enc_path, enc_search, enc_user, enc_fpath, enc_parm
  123. };
  124.  
  125. #if APR_CHARSET_EBCDIC
  126. #define CRLF   "\r\n"
  127. #else /*APR_CHARSET_EBCDIC*/
  128. #define CRLF   "\015\012"
  129. #endif /*APR_CHARSET_EBCDIC*/
  130.  
  131. /* default Max-Forwards header setting */
  132. #define DEFAULT_MAX_FORWARDS    10
  133.  
  134. /* static information about a remote proxy */
  135. struct proxy_remote {
  136.     const char *scheme;        /* the schemes handled by this proxy, or '*' */
  137.     const char *protocol;    /* the scheme used to talk to this proxy */
  138.     const char *hostname;    /* the hostname of this proxy */
  139.     apr_port_t  port;        /* the port for this proxy */
  140.     regex_t *regexp;        /* compiled regex (if any) for the remote */
  141.     int use_regex;        /* simple boolean. True if we have a regex pattern */
  142. };
  143.  
  144. struct proxy_alias {
  145.     const char *real;
  146.     const char *fake;
  147. };
  148.  
  149. struct dirconn_entry {
  150.     char *name;
  151.     struct in_addr addr, mask;
  152.     struct apr_sockaddr_t *hostaddr;
  153.     int (*matcher) (struct dirconn_entry * This, request_rec *r);
  154. };
  155.  
  156. struct noproxy_entry {
  157.     const char *name;
  158.     struct apr_sockaddr_t *addr;
  159. };
  160.  
  161. typedef struct {
  162.     apr_array_header_t *proxies;
  163.     apr_array_header_t *sec_proxy;
  164.     apr_array_header_t *aliases;
  165.     apr_array_header_t *raliases;
  166.     apr_array_header_t *noproxies;
  167.     apr_array_header_t *dirconn;
  168.     apr_array_header_t *allowed_connect_ports;
  169.     const char *domain;        /* domain name to use in absence of a domain name in the request */
  170.     int req;            /* true if proxy requests are enabled */
  171.     char req_set;
  172.     enum {
  173.       via_off,
  174.       via_on,
  175.       via_block,
  176.       via_full
  177.     } viaopt;                   /* how to deal with proxy Via: headers */
  178.     char viaopt_set;
  179.     apr_size_t recv_buffer_size;
  180.     char recv_buffer_size_set;
  181.     apr_size_t io_buffer_size;
  182.     char io_buffer_size_set;
  183.     long maxfwd;
  184.     char maxfwd_set;
  185.     /** 
  186.      * the following setting masks the error page
  187.      * returned from the 'proxied server' and just 
  188.      * forwards the status code upwards.
  189.      * This allows the main server (us) to generate
  190.      * the error page, (so it will look like a error
  191.      * returned from the rest of the system 
  192.      */
  193.     int error_override;
  194.     int error_override_set;
  195.     int preserve_host;
  196.     int preserve_host_set;
  197.     apr_interval_time_t timeout;
  198.     apr_interval_time_t timeout_set;
  199.  
  200. } proxy_server_conf;
  201.  
  202. typedef struct {
  203.     const char *p;            /* The path */
  204.     int         p_is_fnmatch; /* Is this path an fnmatch candidate? */
  205.     regex_t    *r;            /* Is this a regex? */
  206. } proxy_dir_conf;
  207.  
  208. typedef struct {
  209.     conn_rec *connection;
  210.     char *hostname;
  211.     apr_port_t port;
  212.     int is_ssl;
  213. } proxy_conn_rec;
  214.  
  215. typedef struct {
  216.         float cache_completion; /* completion percentage */
  217.         int content_length; /* length of the content */
  218. } proxy_completion;
  219.  
  220.  
  221. /* hooks */
  222.  
  223. /* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and 
  224.  * PROXY_DECLARE_DATA with appropriate export and import tags for the platform
  225.  */
  226. #if !defined(WIN32)
  227. #define PROXY_DECLARE(type)            type
  228. #define PROXY_DECLARE_NONSTD(type)     type
  229. #define PROXY_DECLARE_DATA
  230. #elif defined(PROXY_DECLARE_STATIC)
  231. #define PROXY_DECLARE(type)            type __stdcall
  232. #define PROXY_DECLARE_NONSTD(type)     type
  233. #define PROXY_DECLARE_DATA
  234. #elif defined(PROXY_DECLARE_EXPORT)
  235. #define PROXY_DECLARE(type)            __declspec(dllexport) type __stdcall
  236. #define PROXY_DECLARE_NONSTD(type)     __declspec(dllexport) type
  237. #define PROXY_DECLARE_DATA             __declspec(dllexport)
  238. #else
  239. #define PROXY_DECLARE(type)            __declspec(dllimport) type __stdcall
  240. #define PROXY_DECLARE_NONSTD(type)     __declspec(dllimport) type
  241. #define PROXY_DECLARE_DATA             __declspec(dllimport)
  242. #endif
  243.  
  244. APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, scheme_handler, (request_rec *r, 
  245.                           proxy_server_conf *conf, char *url, 
  246.                           const char *proxyhost, apr_port_t proxyport))
  247. APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, canon_handler, (request_rec *r, 
  248.                           char *url))
  249.  
  250. APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, create_req, (request_rec *r, request_rec *pr))
  251. APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, fixups, (request_rec *r)) 
  252.  
  253. /* proxy_util.c */
  254.  
  255. PROXY_DECLARE(request_rec *)ap_proxy_make_fake_req(conn_rec *c, request_rec *r);
  256. PROXY_DECLARE(int) ap_proxy_hex2c(const char *x);
  257. PROXY_DECLARE(void) ap_proxy_c2hex(int ch, char *x);
  258. PROXY_DECLARE(char *)ap_proxy_canonenc(apr_pool_t *p, const char *x, int len, enum enctype t,
  259.             int isenc);
  260. PROXY_DECLARE(char *)ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp,
  261.              char **passwordp, char **hostp, apr_port_t *port);
  262. PROXY_DECLARE(const char *)ap_proxy_date_canon(apr_pool_t *p, const char *x);
  263. PROXY_DECLARE(apr_table_t *)ap_proxy_read_headers(request_rec *r, request_rec *rp, char *buffer, int size, conn_rec *c);
  264. PROXY_DECLARE(int) ap_proxy_liststr(const char *list, const char *val);
  265. PROXY_DECLARE(char *)ap_proxy_removestr(apr_pool_t *pool, const char *list, const char *val);
  266. PROXY_DECLARE(int) ap_proxy_hex2sec(const char *x);
  267. PROXY_DECLARE(void) ap_proxy_sec2hex(int t, char *y);
  268. PROXY_DECLARE(int) ap_proxyerror(request_rec *r, int statuscode, const char *message);
  269. PROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p);
  270. PROXY_DECLARE(int) ap_proxy_is_domainname(struct dirconn_entry *This, apr_pool_t *p);
  271. PROXY_DECLARE(int) ap_proxy_is_hostname(struct dirconn_entry *This, apr_pool_t *p);
  272. PROXY_DECLARE(int) ap_proxy_is_word(struct dirconn_entry *This, apr_pool_t *p);
  273. PROXY_DECLARE(int) ap_proxy_checkproxyblock(request_rec *r, proxy_server_conf *conf, apr_sockaddr_t *uri_addr);
  274. PROXY_DECLARE(int) ap_proxy_pre_http_request(conn_rec *c, request_rec *r);
  275. PROXY_DECLARE(apr_status_t) ap_proxy_string_read(conn_rec *c, apr_bucket_brigade *bb, char *buff, size_t bufflen, int *eos);
  276. PROXY_DECLARE(void) ap_proxy_table_unmerge(apr_pool_t *p, apr_table_t *t, char *key);
  277. PROXY_DECLARE(int) ap_proxy_connect_to_backend(apr_socket_t **, const char *, apr_sockaddr_t *, const char *, proxy_server_conf *, server_rec *, apr_pool_t *);
  278. PROXY_DECLARE(int) ap_proxy_ssl_enable(conn_rec *c);
  279. PROXY_DECLARE(int) ap_proxy_ssl_disable(conn_rec *c);
  280.  
  281. #endif /*MOD_PROXY_H*/
  282.